package com.ourteam.product.model.dao.impl;

import com.ourteam.product.model.dao.IProductModelDomainDAO;
import com.ourteam.product.model.dao.ProductModelDomain;
import com.ourteam.product.model.dao.ProductModelDomainDAOQueryBean;

import net.dao.AbstractSpringDAO;
import net.dao.DataAccessObjectHelper;

import org.apache.commons.beanutils.PropertyUtils;
import org.apache.commons.lang.StringUtils;

import org.springframework.jdbc.core.RowMapper;

import java.sql.ResultSet;
import java.sql.SQLException;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;


/**
 * Template Name : DAO服务对象
 * Template Version : 1
 * Template Last Modfiy Date : Fri Nov 17 11:00:11 IRKT 2017
 * Auto Generate Date : 2017-11-17 11:01:12
  * Warning ! This file will be overwrite when regenerate !
  *
 */
public class AbstractProductModelDomainDAOJdbcImpl extends AbstractSpringDAO
    implements IProductModelDomainDAO {
    public static final String[] ENTITY_FIELDS = new String[] {
            Id, DomainCode, DomainName, Status, Remarks, CreatorName, CreateTime,
            LastModifierName, LastModifyTime, SubmitterId
        };
    public static final String[] ENTITY_PROPERTIES = new String[] {
            _DataObjectProperty.Id, _DataObjectProperty.DomainCode,
            _DataObjectProperty.DomainName, _DataObjectProperty.Status,
            _DataObjectProperty.Remarks, _DataObjectProperty.CreatorName,
            _DataObjectProperty.CreateTime, _DataObjectProperty.LastModifierName,
            _DataObjectProperty.LastModifyTime, _DataObjectProperty.SubmitterId
        };
    public static final String[] ENTITY_PK_FIELDS = new String[] { Id };
    public static final String[] ENTITY_AUTO_GEN_PK_FIELDS = new String[] { Id };
    public static final String[] ENTITY_UNIQUE_FIELDS = new String[] {  };
    private static String relatedJoinSQL = null;
    private static String basicFilterSQL = null;
    private DataAccessObjectHelper<ProductModelDomain, ProductModelDomainDAOQueryBean> daoHelper;

    public AbstractProductModelDomainDAOJdbcImpl() {
        super();
        daoHelper = new DataAccessObjectHelper<ProductModelDomain, ProductModelDomainDAOQueryBean>(this);
    }

    protected String getEntityName() {
        return EntityName;
    }

    protected String[] getEntityFields() {
        return ENTITY_FIELDS;
    }

    protected String[] getEntityProperties() {
        return ENTITY_PROPERTIES;
    }

    protected String[] getEntityPKFields() {
        return ENTITY_PK_FIELDS;
    }

    protected String[] getEntityAutoGenPKFields() {
        return ENTITY_AUTO_GEN_PK_FIELDS;
    }

    protected String[] getEntityUniqueFields() {
        return ENTITY_UNIQUE_FIELDS;
    }

    protected String getBaiscQueryFilter() {
        if (basicFilterSQL == null) {
            StringBuffer basicFilterSQLbuffer = new StringBuffer();

            basicFilterSQL = basicFilterSQLbuffer.toString();
        }

        return basicFilterSQL;
    }

    protected String getRelatedJoinSQL() {
        if (relatedJoinSQL == null) {
            StringBuffer relatedJoinSQLBuffer = new StringBuffer();

            relatedJoinSQL = relatedJoinSQLBuffer.toString();
        }

        return relatedJoinSQL;
    }

    /**
         * Check Data Unique
         * @param aProductModelDomain
         * @throws Exception
         */
    public boolean checkIsUnique(ProductModelDomain aProductModelDomain)
        throws Exception {
        if (aProductModelDomain == null) {
            return true;
        }

        List valueList = new ArrayList();

        List pkValueList = new ArrayList();

        pkValueList.add(aProductModelDomain.getId());

        return isUnique(valueList.toArray(new Object[valueList.size()]),
            pkValueList.toArray(new Object[pkValueList.size()]));
    }

    /**
     * Insert Data
     * @param aProductModelDomain
     * @throws Exception
     */
    public void insert(ProductModelDomain aProductModelDomain)
        throws Exception {
        super.doInsert(aProductModelDomain);
    }

    /**
         * Batch Insert Datas
         * @param aProductModelDomain
         * @throws Exception
         */
    public void batchInsert(ProductModelDomain[] aProductModelDomains)
        throws Exception {
        super.doBatchInsert(aProductModelDomains);
    }

    /**
         * Delete Data
         * @param  final long id         *
         * @throws Exception
         */
    public void delete(final long id) throws Exception {
        super.doDeleteById(new Object[] { new Long(id) });
    }

    /**
     * Delete Datas
     * @param queryBean
     * @throws Exception
     */
    public void delete(ProductModelDomainDAOQueryBean queryBean)
        throws Exception {
        super.doDeleteByQuery(queryBean);
    }

    public void delete(ProductModelDomain aProductModelDomain)
        throws Exception {
        delete(aProductModelDomain.getId());
    }

    /**
     * Update Data Selective
     * @param aProductModelDomain
     * @throws Exception
     */
    public void update(ProductModelDomain aProductModelDomain)
        throws Exception {
        if (aProductModelDomain.getId() == 0) {
            throw new Exception(
                "Can not update object data whith out primary key value");
        }

        super.doUpdate(aProductModelDomain);

        ProductModelDomain tempObj = findById(aProductModelDomain.getId());

        if (tempObj != null) {
            PropertyUtils.copyProperties(aProductModelDomain, tempObj);
        }
    }

    /**
     * Batch Update Datas
     * @param aProductModelDomains[]
     * @throws Exception
     */
    public void batchUpdate(ProductModelDomain[] aProductModelDomains)
        throws Exception {
        super.doBatchUpdate(aProductModelDomains);
    }

    /**
         * Update Data By Condictions
         * @param aProductModelDomain
         * @param aValueCriteria
         * @param aTransaction
         * @throws Exception
         */
    public void update(ProductModelDomain aProductModelDomain,
        ProductModelDomainDAOQueryBean aQueryBean) throws Exception {
        super.doUpdateByQuery(aProductModelDomain, aQueryBean);
    }

    /**
     * Update Data By Condictions
     * @param aQueryBean
     * @throws Exception
     */
    public void update(ProductModelDomainDAOQueryBean aQueryBean)
        throws Exception {
        super.doUpdateByQuery(aQueryBean);
    }

    protected void checkNullValue(ProductModelDomain aProductModelDomain)
        throws Exception {
        if (aProductModelDomain.getDomainCode() == null) {
            throw new Exception(
                "The ProductModelDomain.domainCode value is not allow NULL");
        }

        if (aProductModelDomain.getDomainName() == null) {
            throw new Exception(
                "The ProductModelDomain.domainName value is not allow NULL");
        }

        if (aProductModelDomain.getStatus() == null) {
            throw new Exception(
                "The ProductModelDomain.status value is not allow NULL");
        }

        if (aProductModelDomain.getRemarks() == null) {
            throw new Exception(
                "The ProductModelDomain.remarks value is not allow NULL");
        }
    }

    /**
     * Get Data By ID
     * @param  final long id         * @return  ${businessObject.name}
     * @throws Exception
     */
    public ProductModelDomain findById(final long id) throws Exception {
        ProductModelDomainDAOQueryBean queryBean = new ProductModelDomainDAOQueryBean();

        ProductModelDomainDAOQueryBean.Criteria criteria = queryBean.createCriteria();

        criteria.andIdEqualTo(id);

        //queryBean.setDistinct(true);
        ProductModelDomain[] ProductModelDomains = query(queryBean);

        if (ProductModelDomains.length == 0) {
            return null;
        } else {
            return ProductModelDomains[0];
        }
    }

    /**
         * Query Data
         * @param queryBean
         * @return ProductModelDomain[]
         * @throws Exception
         */
    public ProductModelDomain[] query(ProductModelDomainDAOQueryBean queryBean)
        throws Exception {
        List result = super.doQuery(queryBean,
                new JdbcProductModelDomainRowMapper());

        return (ProductModelDomain[]) result.toArray(new ProductModelDomain[result.size()]);
    }

    /**
     * Query ${businessObject.name} Selective
     * @param queryBean
     * @return Map[]
     * @model
     * @throws Exception
     */
    public Map<String, Object>[] querySelective(
        ProductModelDomainDAOQueryBean queryBean) throws Exception {
        if (queryBean.getSelectProperties().isEmpty()) {
            queryBean.addAllSelectProperties();
        }

        return super.doQuerySelective(queryBean);
    }

    /**
     * Query Data Count
     * @param queryBean
     * @return int
     * @throws Exception
     */
    public int queryCount(ProductModelDomainDAOQueryBean queryBean)
        throws Exception {
        return super.doQueryCount(queryBean);
    }

    public void synchronize(ProductModelDomain[] aProductModelDomains,
        ProductModelDomainDAOQueryBean queryBean) throws Exception {
        daoHelper.synchronize(aProductModelDomains, queryBean);
    }

    public void synchronize(ProductModelDomain[] aProductModelDomains,
        ProductModelDomainDAOQueryBean queryBean,
        net.dao.IDataAccessInterface.ISynchronizeCallback<ProductModelDomain> callBack)
        throws Exception {
        daoHelper.synchronize(aProductModelDomains, queryBean, callBack);
    }

    public static class JdbcProductModelDomainRowMapper implements RowMapper<ProductModelDomain> {
        public ProductModelDomain mapRow(ResultSet resultSet, int arg1)
            throws SQLException {
            ProductModelDomain object = new ProductModelDomain();

            int columnIndex = 1;

            int __dataType;

            try {
                Object id = null;

                id = resultSet.getObject(columnIndex++);

                object.setIdNull(resultSet.getBoolean(columnIndex++));

                if (id != null) {
                    setBeanValue(object, _DataObjectProperty.Id, id);
                }

                Object domainCode = null;

                domainCode = resultSet.getObject(columnIndex++);

                object.setDomainCodeNull(resultSet.getBoolean(columnIndex++));

                if (domainCode != null) {
                    setBeanValue(object, _DataObjectProperty.DomainCode,
                        domainCode);
                }

                Object domainName = null;

                domainName = resultSet.getObject(columnIndex++);

                object.setDomainNameNull(resultSet.getBoolean(columnIndex++));

                if (domainName != null) {
                    setBeanValue(object, _DataObjectProperty.DomainName,
                        domainName);
                }

                Object status = null;

                status = resultSet.getObject(columnIndex++);

                object.setStatusNull(resultSet.getBoolean(columnIndex++));

                if (status != null) {
                    setBeanValue(object, _DataObjectProperty.Status, status);
                }

                Object remarks = null;

                remarks = resultSet.getObject(columnIndex++);

                object.setRemarksNull(resultSet.getBoolean(columnIndex++));

                if (remarks != null) {
                    setBeanValue(object, _DataObjectProperty.Remarks, remarks);
                }

                Object creatorName = null;

                creatorName = resultSet.getObject(columnIndex++);

                object.setCreatorNameNull(resultSet.getBoolean(columnIndex++));

                if (creatorName != null) {
                    setBeanValue(object, _DataObjectProperty.CreatorName,
                        creatorName);
                }

                Object createTime = null;

                __dataType = resultSet.getMetaData().getColumnType(columnIndex);

                if ((__dataType == java.sql.Types.DATE) ||
                        (__dataType == java.sql.Types.TIME) ||
                        (__dataType == java.sql.Types.TIMESTAMP)) {
                    createTime = resultSet.getTimestamp(columnIndex++);
                } else {
                    createTime = resultSet.getObject(columnIndex++);
                }

                object.setCreateTimeNull(resultSet.getBoolean(columnIndex++));

                if (createTime != null) {
                    setBeanValue(object, _DataObjectProperty.CreateTime,
                        createTime);
                }

                Object lastModifierName = null;

                lastModifierName = resultSet.getObject(columnIndex++);

                object.setLastModifierNameNull(resultSet.getBoolean(
                        columnIndex++));

                if (lastModifierName != null) {
                    setBeanValue(object, _DataObjectProperty.LastModifierName,
                        lastModifierName);
                }

                Object lastModifyTime = null;

                __dataType = resultSet.getMetaData().getColumnType(columnIndex);

                if ((__dataType == java.sql.Types.DATE) ||
                        (__dataType == java.sql.Types.TIME) ||
                        (__dataType == java.sql.Types.TIMESTAMP)) {
                    lastModifyTime = resultSet.getTimestamp(columnIndex++);
                } else {
                    lastModifyTime = resultSet.getObject(columnIndex++);
                }

                object.setLastModifyTimeNull(resultSet.getBoolean(columnIndex++));

                if (lastModifyTime != null) {
                    setBeanValue(object, _DataObjectProperty.LastModifyTime,
                        lastModifyTime);
                }

                Object submitterId = null;

                submitterId = resultSet.getObject(columnIndex++);

                object.setSubmitterIdNull(resultSet.getBoolean(columnIndex++));

                if (submitterId != null) {
                    setBeanValue(object, _DataObjectProperty.SubmitterId,
                        submitterId);
                }

                return object;
            } catch (Exception e) {
                throw new SQLException(e.getMessage());
            }
        }
    }
}
